package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper {


    Page<Orders> findByPage(OrdersPageQueryDTO ordersPageQueryDTO);

    void save(Orders orders);

    Orders findByUserIdAndNumber(Long userId, String outTradeNo);

    void update(Orders orders);

    @Select("SELECT * FROM `orders` WHERE `id` = #{orderId}")
    Orders findById(Long orderId);

    @Select("select count(id) from orders where status = #{status}")
    Integer countStatus(Integer toBeConfirmed);

    /**
     * 根据状态和下单时间查询订单
     * @param status
     * @param orderTime
     */
    @Select("select * from orders where status = #{status} and order_time < #{orderTime}")
    List<Orders> getByStatusAndOrdertimeLT(Integer status, LocalDateTime orderTime);

    Integer countByMap(Map map);

    /**
     * 根据动态条件统计营业额
     * @param map
     */
    Double sumByMap(Map map);
}
